/**
 * Created by LinJe on 2015/9/22.
 * 全局ui：登陆提示 弹窗
 */
(function( $, window ) {

    window.globalLayer = window.globalLayer || {};


    /**
     * 调用实例
     * window.globalLayer.openLogin({'callBack':function() {
            console.log('登陆提示窗已关闭');
       }});
     * @param settings
     */
    window.globalLayer.openDelete = function( settings ) {

        var deleteArgs;

        //如果是第一次调用，加载弹窗所需html和js变量
        if ( !this.deleteArgs ) {
            $('body').append('\
                <div class="layer_delete">\
                    <div class="popup-bg"></div>\
                    <div class="popup del-info">\
                        <div class="content">\
                            <div class="title clearfix"><div class="btn"><span class="close" title="关闭"></span></div></div>\
                            <div class="text-con"><p>确认删除此条信息？</p></div>\
                            <div class="button"><button type="button" class="button-3">删除</button><button type="button" class="button-2">取消</button></div>\
                        </div>\
                    </div>\
            </div>\
            ');

            deleteArgs = this.deleteArgs = {};
            deleteArgs.$deleteWrap = $('.layer_delete');
            deleteArgs.$colse = deleteArgs.$deleteWrap.find('.title .btn');
            deleteArgs.$cancle = deleteArgs.$deleteWrap.find('.button .button-2');
            deleteArgs.$delete = deleteArgs.$deleteWrap.find('.button .button-3');

            //点击取消或者X 关闭弹窗
            deleteArgs.$colse.on('click', function() { window.globalLayer.closeDelete(deleteArgs.callBack) });
            deleteArgs.$cancle.on('click', function() { window.globalLayer.closeDelete(deleteArgs.callBack) });

            //点击 删除信息
            deleteArgs.$delete.on('click', function() {
                window.globalLayer.closeDelete(function() {
                    //回调
                    deleteArgs.callBack(true);
                })
            });
        }

        deleteArgs = this.deleteArgs;
        $.extend(deleteArgs, settings);

        deleteArgs.$deleteWrap.css({'opacity':'0', 'display':'block'}).stop().animate({ 'opacity': 1 });
    };


    window.globalLayer.closeDelete = function( callBack ) {

        this.deleteArgs.$deleteWrap.stop().animate({ 'opacity': 0 }, 500, '', function() {
            $(this).hide();
            callBack && callBack();
        });

    };

})( jQuery, window );